package cn.marinda.listener;

import cn.marinda.entity.ServerProcess;

import javax.swing.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

/**
 * 发送命令按键事件
 *
 * @author admin
 * @date 2022/08/02
 */
public class SendCommandKeyEvent implements KeyListener {
    private JTextField textField;
    private JTextArea textArea;
    public SendCommandKeyEvent(JTextField textField,JTextArea textArea){
     this.textField = textField;
     this.textArea = textArea;
    }
    @Override
    public void keyTyped(KeyEvent e) {

    }

    @Override
    public void keyPressed(KeyEvent e) {
        if(e.getKeyCode() == 10){
            String command = textField.getText();
            ServerProcess.instance.sendCommandToServer(command);
            textField.setText("");
            textArea.selectAll();
        }
    }

    @Override



    public void keyReleased(KeyEvent e) {

    }
}
